<template>
  <div>
    <el-card class="box-card">
      <div slot="header" style="text-align:left">
        <el-form :inline="true" :model="searchForm" class="demo-form-inline">
          <el-form-item label="企业名称">
            <el-input v-model="searchForm.key" placeholder="企业名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table :data="companies" border style="width: 100%">
        <el-table-column prop="name" label="企业名称" style="width: 20%"></el-table-column>
        <el-table-column prop="area" label="地区" style="width: 50%"></el-table-column>
        <el-table-column prop="legalPerson" label="法人" style="width: 50%"></el-table-column>
        <el-table-column prop="phone" label="电话" style="width: 50%"></el-table-column>
        <el-table-column prop="examined" label="审核" style="width: 50%">
             <template slot-scope="scope">
                  <span style="color:green" v-if="scope.row.examined">通过</span>
                  <span style="color:red" v-else>驳回</span>
              </template>
        </el-table-column>
        <el-table-column prop="expiretime" label="有效期" style="width: 50%">
             <template slot-scope="scope">
                  {{(scope.row.expiretime)}} 
                  <span style="color:red" v-if="new Date(scope.row.expiretime)<=new Date()">过期</span>
              </template>
        </el-table-column>
        <el-table-column prop="createtime" label="注册时间" style="width: 50%"></el-table-column>
    
        <el-table-column label="操作" style="width: 10%">
          <template slot-scope="scope">
            <!-- <el-button type="text" size="small" @click="detail(scope.row)">查看</el-button> -->
            <el-button type="text" size="small" @click="torole(scope.row)">功能</el-button>
            <!-- <el-button type="text" size="small" @click="edit(scope.row)">编辑</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top:10px;">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page.sync="pagenow"
          :page-size="pagesize"
          layout="total, prev, pager, next"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
   

  </div>
</template>

<script>
import { goverment_findByList } from "@/request/api.js";
export default {
  methods: {
    handleCurrentChange(p) {
      // console.log(this.pagenow)
      // console.log(this.searchForm.key)
      this.loadPage(p);
    },
    onSubmit() {
      this.pagenow = 1;
      this.loadPage();
    },
    loadPage() {
      var param = { pagesize: 10, page: this.pagenow,"name":this.searchForm.key};
      goverment_findByList(param).then(res => {
        this.companies = res.rows;
        this.total = res.total;
      });
    },
    detail(row){
      this.$router.push({"path":"/view",query:{"id":row.id}});
    },
     edit(row){
      this.$router.push({"path":"/add",query:{"id":row.id}});
    },
    torole(row){
       this.$router.push({"path":"/resources","query":{id:row.id,name:row.name}});
    }
  },
 
  mounted() {
    this.loadPage();
  },

  data() {
    return {
      companies: [],
      total: 0,
      pagenow: 1,
      pagesize: 10,
      roles:[],
      reload:false,
      chooseRoles:[],
      chooseRow:{},
      searchForm: {
        key: ""
      }
    };
  }
};
</script>